package com.wefans.wefansapp.common.tool.preference;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

import com.wefans.wefansapp.common.tool.debug.MFDebug;

public class MFSharedPreference 
{
	private static final String	TAG_LOG	= "SettingPreference";
	SharedPreferences mPreference;
	Context context;
	
	public MFSharedPreference(Context context)
	{
		this.context = context;
		mPreference = context.getSharedPreferences("SettingPre", Activity.MODE_PRIVATE);
	}
	
	/**
	 * mem_idx
	 * @param id
	 */
	public void setMem_idx(String id)
	{
		MFDebug.e(TAG_LOG, "SAVE !!! ===  setMem_idx = "+id);
		SharedPreferences.Editor edit = mPreference.edit();
		edit.putString("Mem_idx", id);
		edit.commit();
	}
	
	public String getMem_idx()
	{
		String id = mPreference.getString("Mem_idx", "");
		return id; 
	}
	
	public void setMem_type(String type)
	{
		MFDebug.e(TAG_LOG, "SAVE !!! ===  setMem_type = "+type);
		SharedPreferences.Editor edit = mPreference.edit();
		edit.putString("Mem_type", type);
		edit.commit();
	}
	
	public String getMem_type()
	{
		String id = mPreference.getString("Mem_type", "");
		return id; 
	}
	
	/**
	 * 최초실헹!!
	 * @param auto
	 */
	public void setFirstLaunch(boolean isFrist)
	{
		SharedPreferences.Editor edit = mPreference.edit();
		edit.putBoolean("isFrist", isFrist);
		edit.commit();
	}
	
	public boolean isFirstLaunch()
	{
		boolean isFrist = mPreference.getBoolean("isFrist", true);
		return isFrist; 
	}
	
	private void setCheckDailyDate(String strDate)
	{
		SharedPreferences.Editor edit = mPreference.edit();
		edit.putString("Check_Daily", strDate);
		edit.commit();
	}
	
	private String getCheckDailyDate()
	{
		String strDate = mPreference.getString("Check_Daily", "");
		
		return strDate;
	}
	
	public boolean isShowDaily()
	{
		boolean bRet = true;
		
		String strLastDate = getCheckDailyDate();
		
		if (strLastDate != null && strLastDate.length() > 0) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
			String currentDateandTime = sdf.format(new Date());
			
			if (strLastDate.equals(currentDateandTime)) {
				bRet = false;
			}
		}
		
		return bRet;
	}
	
	public void setShowDaily() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String currentDateandTime = sdf.format(new Date());
		
		setCheckDailyDate(currentDateandTime);
	}
}
